@extends('admin.base')
@section('css')
@parent

@stop



@section('content')
<link rel="stylesheet" href="/css/parsley/parsley.css"/>
<link rel="stylesheet" href="/css/sweetalert/sweetalert.css"/>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-sm-4">
        <h2>菜单</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{{route('/')}}">首页</a>
            </li>
            <li>
                @if ($edit_mode == 1)
                <strong>编辑微信菜单</strong>
                @else
                <strong>新建微信菜单</strong>
                @endif
            </li>
        </ol>
    </div>
    <div class="col-sm-8">
        <div class="title-action">
            <a href="{{route('menu.index')}}" class="btn btn-primary newmenu">返回菜单列表</a>
        </div>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRightBig">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>自定义菜单<small>：）</small></h5>
                    <div class="ibox-tools">
                        <a href="{{route('newmenu')}}" class="btn btn-primary btn-xs newmenu">提交完一级菜单点一下这里~</a>
                    </div>
                </div>
                <div class="ibox-content">
                    @if ($edit_mode == 1)
                    <form method="POST" action="{{route('menu.update', $id)}}" class="form-horizontal" id="submitmenu" data-parsley-validate>
                        <input name="_method" type="hidden" value="PUT">
                        @else
                        <form method="POST" action="{{route('menu.store')}}" class="form-horizontal" id="submitmenu" data-parsley-validate>
                            @endif
                            <div class="form-group">
                                <label class="col-sm-2 control-label">菜单名</label>
                                <div class="col-sm-10">
                                    @if ($edit_mode == 1)
                                    <input type="text" name="menuname" class="form-control" value="{{$menuinfo->menuname}}" placeholder="输入菜单名，最好不要太长哦" required data-parsley-errors-container="#menuname">
                                    @else
                                    <input type="text" name="menuname" class="form-control" placeholder="输入菜单名，最好不要太长哦" required data-parsley-errors-container="#menuname">
                                    @endif
                                    <span class="help-block m-b-none" id="menuname"></span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">排序号</label>
                                <div class="col-sm-10">
                                    @if ($edit_mode == 1)
                                    <input type="text" name="menuvalue" class="form-control" value="{{$menuinfo->menuvalue}}" placeholder="数值越小越靠前" required data-parsley-type="number" data-parsley-errors-container="#menuvalue">
                                    @else
                                    <input type="text" name="menuvalue" class="form-control" placeholder="数值越小越靠前" required data-parsley-type="number" data-parsley-errors-container="#menuvalue">
                                    @endif
                                    <span class="help-block m-b-none" id="menuvalue"></span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">所属菜单</label>

                                <div class="col-sm-10">
                                    <select class="form-control m-b" name="belongto" required>
                                        @if ($edit_mode == 1)
                                        <option value="">选择。。。</option>
                                        @if ($menuinfo->belongto == 0)
                                        <option value="0" selected>无</option>
                                        @else
                                        <option value="0">无</option>
                                        @endif
                                        @foreach ($headmenus as $headmenu)
                                        @if ($headmenu->id == $menuinfo->belongto)
                                        <option value="{{$headmenu->id}}" selected>{{$headmenu->menuname}}</option>
                                        @else
                                        <option value="{{$headmenu->id}}">{{$headmenu->menuname}}</option>
                                        @endif
                                        @endforeach
                                        @else
                                        <option value="">选择。。。</option>
                                        <option value="0">无</option>
                                        @foreach ($headmenus as $headmenu)
                                        <option value="{{$headmenu->id}}">{{$headmenu->menuname}}</option>
                                        @endforeach
                                        @endif
                                    </select>
                                    <span class="help-block m-b-none">最多可建3个一级菜单</span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">菜单类型</label>

                                <div class="col-sm-10">
                                    <select class="form-control m-b" name="menutype" required>
                                        @if($edit_mode == 1)
                                        @if ($menuinfo->menutype == 1)
                                        <option value="1" selected>无事件的一级菜单</option>
                                        @else
                                        <option value="1">无事件的一级菜单</option>
                                        @endif
                                        @if ($menuinfo->menutype == 2)
                                        <option value="2" selected>点击推事件</option>
                                        @else
                                        <option value="2">点击推事件</option>
                                        @endif
                                        @if ($menuinfo->menutype == 3)
                                        <option value="3" selected>跳转URL</option>
                                        @else
                                        <option value="3">跳转URL</option>
                                        @endif
                                        @else
                                        <option value="1">无事件的一级菜单</option>
                                        <option value="2">点击推事件</option>
                                        <option value="3">跳转URL</option>
                                        @endif
                                    </select>

                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">关键词</label>
                                <div class="col-sm-10">
                                    @if ($edit_mode == 1)
                                    <input type="text" name="menukeyword" class="form-control" value="{{$menuinfo->menukeyword}}" placeholder="根据类型填写不同的值：不填或者触发KEY或者跳转URL">
                                    @else
                                    <input type="text" name="menukeyword" class="form-control"  placeholder="根据类型填写不同的值：不填或者触发KEY或者跳转URL">
                                    @endif
                                    <span class="help-block m-b-none" id="menukeyword"></span>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    @if ($edit_mode == 1)
                                    <button class="btn btn-primary editmenu" type="submit">保存内容</button>
                                    @else
                                    <button class="btn btn-primary submitmenu" type="submit">保存内容</button>
                                    @endif
                                </div>
                            </div>
                        </form>
                </div>
            </div>
        </div>
    </div>
</div>

@stop

@section('script')
@parent
<script src="/js/parsley/parsley.min.js"></script>
<script src="/js/parsley/parsley.extend.js"></script>
<script src="/js/parsley/zh_cn.js"></script>
<script src="/js/jqForm/jquery.form.min.js"></script>
<script src="/js/sweetalert/sweetalert.min.js"></script>
<script>
    $('.submitmenu').on('click', function() {
        var formOptions = {
            //clearForm: true,
            beforeSubmit : function() {
                console.log('test form success!');
                //window.Parsley.setLocale('zh_cn');
                var $parsley_result = $('#submitmenu').parsley();
                console.log($parsley_result);
            },
            success : function(data) {
                console.log('submited!');
                if(data.code!=2000) {console.log('submit form failed');
                    sweetAlert("Oops...", data.message, "error");
                    return false;
                }else {
                    console.log('submit form success!');
                    swal("Good job!", "新增菜单成功!", "success");
                    $('#submitmenu').resetForm();
                }

            }
        }
        $('#submitmenu').ajaxForm(formOptions);

    });

    $('.editmenu').on('click', function() {
        var formOptions = {
            //clearForm: true,
            beforeSubmit : function() {
                console.log('test form success!');
                //window.Parsley.setLocale('zh_cn');
                var $parsley_result = $('#submitmenu').parsley();
                console.log($parsley_result);
            },
            success : function(data) {
                console.log('submited!');
                if(data.code!=2000) {console.log('submit form failed');
                    sweetAlert("Oops...", data.message, "error");
                    return false;
                }else {
                    console.log('submit form success!');
                    swal("Good job!", "修改菜单成功!", "success");
                }

            }
        }
        $('#submitmenu').ajaxForm(formOptions);

    });
</script>
@stop
